#include <main.h>
//SLAVE

volatile int RXByte = 0x00;				//holds the most recent byte received from the master

	   
       #INT_SSP
	   void  SSP_isr(void) 				
		{
			
    	 int8 I2CState = i2c_isr_state();		//reads the current I2C state
		if(I2CState == 0)			//if 0, then address received
		{
		  i2c_read();				//used to clear the buffer after receiving the address byte
		}
		  else if(I2CState == 1)		//if 1, then data byte received
		{
		  RXByte = i2c_read();      		//read actual data byte sent by master
		}
		}
void main()
{
	enable_interrupts(INT_SSP);			//enable I2C interrupt
	enable_interrupts(GLOBAL);			//enable global interrupt handling

	while(TRUE)
	{
	  if(RXByte & 0B00000001)			//looking at indicator LED pin (Slave - A0)
	  {
		output_high(INDICATOR_LED);		//Indicator LED ON
		delay_ms(500);				//wait 500ms
		output_low(INDICATOR_LED);		//Indicator LED OFF
		delay_ms(500); 				//wait 500ms
	  } 
	  else if(RXByte & 0B00000010)			//looking at hazards LED pin (Slave - A1)
	  {
		output_high(HAZARDS_LED);		//Hazards LED ON
		delay_ms(500);				//wait 500ms
		output_low(HAZARDS_LED);		//Hazards LED OFF
		delay_ms(500); 				//wait 500ms
	  }
	  output_a(RXByte & 0B00001100);		//looks at Brake and Reverse LED pins (A2 & A3)
							//written directly to port A as they do not need to blink
	}
}
